# selenium对cookie的处理
from selenium import webdriver
import time

url = "https://www.baidu.com"

driver = webdriver.Chrome("./chromedriver")

driver.get(url)
time.sleep(3)

# 1.获取cookie
# driver.get_cookies()返回列表，其中包含的是完整的cookie信息
# 获取当前标签页的全部cookie信息
print(driver.get_cookies())
# 把cookie转化为字典
cookies_dict = {cookie['name']: cookie['value'] for cookie in driver.get_cookies()}
print(cookies_dict)
# import requests
# requests 模块使用cookie,需要转换为name、value作为键值对的cookie字典
# requests.get(url, cookies=cookies_dict)

# 2.删除cookie
# # 删除一条cookie
# driver.delete_cookie("CookieName")
#
# # 删除所有的cookie
# driver.delete_all_cookies()

driver.quit()
